package com.sip.stream.utils.zfy.adapter;

import android.view.View;
import androidx.recyclerview.widget.RecyclerView;
import androidx.viewbinding.ViewBinding;

import com.sip.stream.utils.zfy.listener.DataBindingViewHolderClickListener;

public abstract class BaseDataBindingViewHolder<VDB extends ViewBinding, M> extends RecyclerView.ViewHolder {
    protected M bean;
    protected VDB binding;
    protected int index;
    protected DataBindingViewHolderClickListener<M> onClickListener;

    public BaseDataBindingViewHolder(VDB vdb, DataBindingViewHolderClickListener<M> dataBindingViewHolderClickListener) {
        super(vdb.getRoot());
        this.onClickListener = dataBindingViewHolderClickListener;
        this.binding = vdb;
        this.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (BaseDataBindingViewHolder.this.onClickListener == null || BaseDataBindingViewHolder.this.bean == null) {
                    return;
                }
                BaseDataBindingViewHolder.this.onClickListener.onClick(BaseDataBindingViewHolder.this.index, BaseDataBindingViewHolder.this.bean);
            }
        });
    }

    public void onBindViewHolder(int index, M bean) {
        this.index = index;
        this.bean = bean;
    }

    public M getBean() {
        return this.bean;
    }
}
